// echo partial file, should not compile along

using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections.Generic;
using HarmonyLib;
using Utils;
namespace GongfaEffect;

public partial class GongfaEffect {
//! 虽然这里只是洗头小妹mod，但我们可以很轻松愉快地借用此处逻辑控制各种过月行为，比如在PeriAdvanceMonth_ExecuteGeneralAction搞一个追着太吾指点武功的行为。
    public static class DaTaiYin_Old {
//! 首先，请允许我介绍一下partial class这个神器。这个神器允许我们把一个大类拆成很多个小文件。用的时候把文件拼起来就可以了。
//! 这里需要注意一点，写作Config.PersonalNeed.DefKey.MakeLove的这个东西是一个常数，而这个常数随时会被茄子改掉，所以需要用反射，在启动Mod时更新这些常数。
        public static short DefKey_VirginityTrue = Config.CharacterFeature.DefKey.VirginityTrue;
        public static short DefKey_VirginityFalse = Config.CharacterFeature.DefKey.VirginityFalse;
        public static short DefKey_Pregnant = Config.CharacterFeature.DefKey.Pregnant;
        public const short Defkey_DaTaiYin=55; // 目前这个方法并没有被暴露在defkey之外，因此只能如此使用。
        public static void Patch(RobustHarmonyInstance HarmonyInstance, string ModIdStr){
            DefKey_VirginityTrue=(short)typeof(Config.CharacterFeature.DefKey).GetField("VirginityTrue",(BindingFlags)(-1)).GetValue(null);
            DefKey_VirginityFalse=(short)typeof(Config.CharacterFeature.DefKey).GetField("VirginityFalse",(BindingFlags)(-1)).GetValue(null);
            DefKey_Pregnant=(short)typeof(Config.CharacterFeature.DefKey).GetField("Pregnant",(BindingFlags)(-1)).GetValue(null);
            HarmonyInstance.PatchAll(System.Reflection.MethodBase.GetCurrentMethod().ReflectedType);
        }
//! 这里跟冰清玉洁一样，我们需要选择合适的注入位置。比如UpdateLuckEvents就很不错，这是针对每一个人的，太吾并不能幸免。
        public static MethodInfo AddElement_PregnantStates=typeof(GameData.Domains.Character.CharacterDomain).GetMethod("AddElement_PregnantStates",(BindingFlags)(-1));
        [HarmonyPrefix]
        [HarmonyPatch(typeof(GameData.Domains.Character.CharacterDomain),"UpdateLuckEvents")]
        public static void Prefix(GameData.Common.DataContext context, Dictionary<int,GameData.Domains.Character.Character> ____objects) {
            GameData.Domains.CombatSkill.CombatSkill cs;
            foreach (var character in ____objects.Values) {
                if(GameData.Domains.DomainManager.CombatSkill.TryGetElement_CombatSkills(new GameData.Domains.CombatSkill.CombatSkillKey(character.GetId(), Defkey_DaTaiYin),out cs) // 要练大太阴的
                    && character.GetGender() == 0 // 要妹子
                ) {
                    var loc=character.GetLocation();
                    var cid=character.GetId();
                    var currDate=GameData.Domains.DomainManager.World.GetCurrDate();
                    GameData.Domains.LifeRecord.LifeRecordCollection lifeRecordCollection = GameData.Domains.DomainManager.LifeRecord.GetLifeRecordCollection();
                    foreach(var type in new ushort[]{1,2,4,8,16,32,64,128,256,512,1024}){
                        var list=new List<int>(GameData.Domains.DomainManager.Character.GetRelatedCharIds(cid,type)); // 下面更改GetRelatedCharIds时会迭代器失效，这里必须存一下这个list
                        foreach(var related in list){
                            lifeRecordCollection.AddDumpLover(cid,currDate,related,loc);
                            GameData.Domains.DomainManager.Character.ChangeRelationType(context, cid, related,  type , 0);
                            GameData.Domains.DomainManager.Character.ChangeRelationType(context, related, cid,  type , 16384);
                        }
                    }
                }
            }
        }
    }
}
